package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.mystery;

import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.Vec3d;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import javax.swing.text.html.parser.Entity;

public class SnipeSkill extends BaseSkill {

    public SnipeSkill(int level){super(level);}

    public SnipeSkill(NbtCompound nbtCompound){super(nbtCompound);}

    public SnipeSkill(){
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        if(skillConfig.getCooldown() == null){
            skillConfig.setCooldown(100);//20tick为1秒
        }
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return super.getDefaultConfig();
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        return "发射一根高速且伤害巨大的箭";
    }

    public SkillRarity getSkillRarity(){return SkillRarity.Mystery;}

    @Override
    public boolean canUseAbility(MobEntity mobEntity) {
        return mobEntity.world.getTime()>getSkilltime();
    }

    @Override
    public boolean onAbilityUse(MobEntity mobEntity) {
        LivingEntity target = mobEntity.getTarget();
        if(target != null && canUseAbility(mobEntity))
        {
            ProjectileEntity arrow = EntityType.ARROW.create(mobEntity.world);
            arrow.setOwner(mobEntity);
            double X = target.getX() - mobEntity.getX();
            double Y = target.getY() - mobEntity.getY();
            double Z = target.getZ() - mobEntity.getZ();
            Vec3d vec3d = new Vec3d(X,Y,Z);
            arrow.updatePosition(mobEntity.getX(),mobEntity.getY()+1.7d,mobEntity.getZ());
            arrow.updateVelocity(getSkillLevel()/2+5.0f, vec3d);
            //MC中箭矢伤害=速度*基础伤害,向上取整
            mobEntity.world.spawnEntity(arrow);
            setSkilltime(target.world.getTime()+getCooldown());
        }
        return true;
    }
}
